<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
class Question extends Common
{
    public function index(){
        $question=Db::query("select q_id,q_answer,q_time,m_name,q_intro,u_name,u_time from masters m,questions q,users u where m.m_id=q.m_id and q.u_id=u.u_id");
        $this->assign("question",$question);
        return $this->fetch();
    }
  /*  public function form(){
        return $this->fetch();
    }
    public function add(){
        $data=[
            'ac_name'=>input('ac_name'),
            'ac_address'=>input('ac_address'),
            'ac_time'=>input('ac_time'),
            'ac_num'=>input('ac_num'),
            'ac_price'=>input('ac_price'),
            'ac_intro'=>input('ac_intro'),
            'ac_tel'=>input('ac_tel')

        ];
        if (Db::name('Questions')->insert($data)){
            $this->success('添加成功','Question/index');
        }else $this->error('添加失败');
        return $this->fetch();
    }

    public function mod($id){
        $question=Db::name("Questions")->find($id);
        $this->assign("question",$question);
        return $this->fetch();
    }*/
   



    public function delete($id){
        if (Db::name("Questions")->delete($id)){
            $this->success('删除成功');
        }else $this->error('删除失败');
    }



    public function search(){
        $key=input('key');
        // dump($key);exit;
        if(!$key){
            $this->success('无搜索内容','Question/index');
        }else{
            $question=Db::table('Questions')->where('q_answer','like','%'.$key.'%')->select();
            $this->assign("question",$question);
            // dump($activity);exit;
            return $this->fetch('index');

        }

        // dump($sql);
    }
    public function jiekou(){

        $rs=Db::name('Questions')->select();
        return json($rs);
    }

}